﻿<Window x:Class="Albatross.Shell.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:commonViews="clr-namespace:Albatross.WPF.Common.Views;assembly=Albatross.WPF.Common"
        Title="Albatross Shell" Height="400" Width="600"
		Background="{x:Static SystemColors.ControlBrush}" 
		SnapsToDevicePixels="True" Closing="Window_Closing">
	<Window.Icon>
		<BitmapImage UriSource="/images/App_32.png" DecodePixelHeight="32" DecodePixelWidth="32"/>
	</Window.Icon>
	
	<Window.Resources>
		<SolidColorBrush x:Key="tabcontrol_border" Color="Silver"/>
		<Color x:Key="tabcontrol_backgroundcolor">White</Color>
		<SolidColorBrush x:Key="tabcontrol_background" Color="{StaticResource tabcontrol_backgroundcolor}"/>
		
		<Image x:Key="new app img" Source="Images\NewApp.png" Width="16" Height="16"/>
		<Image x:Key="options img" Source="Images\Options.png" Width="16" Height="16"/>
		<Image x:Key="system img" Source="Images\ToolBox.png" Width="16" Height="16"/>
		<Image x:Key="about img" Source="Images\About.png" Width="16" Height="16"/>
		<Image x:Key="exit img" Source="Images\Exit.png" Width="16" Height="16"/>
		<Image x:Key="favorite img" Source="Images\Favorite.png" Width="16" Height="16"/>

		<Style x:Key="workspace_menuitem" TargetType="MenuItem">
			<Setter Property="Header" Value="{Binding Header}"/>
			<Setter Property="IsCheckable" Value="True"/>
			<Setter Property="IsChecked" Value="{Binding IsSelected, Mode=TwoWay}"/>
		</Style>

		<ContextMenu x:Key="tabitem_contextmenu">
			<MenuItem Header="Close" />
			<MenuItem Header="Close All" Click="CloseAllMenuItem_Click" />
			<MenuItem Header="Close All But This" />
			<Separator/>
			<MenuItem Header="Save as Favorite" />
			<MenuItem Header="Pop out"/>
		</ContextMenu>

		<Style TargetType="{x:Type TabItem}" x:Key="tabitem">
			<Setter Property="ContextMenu" Value="{StaticResource tabitem_contextmenu}"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type TabItem}">
						<Border x:Name="Border" BorderThickness="0 1 1 0" Background="LightGray" BorderBrush="{StaticResource tabcontrol_border}" HorizontalAlignment="Stretch">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="TabItemStates">
									<VisualState x:Name="Selected">
										<Storyboard>
											<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
												<EasingColorKeyFrame KeyTime="0" Value="{StaticResource tabcontrol_backgroundcolor}" />
											</ColorAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="Normal" />
									<VisualState x:Name="MouseOver">
										<Storyboard>
											<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
												<EasingColorKeyFrame KeyTime="0" Value="Transparent" />
											</ColorAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="Disabled" />
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<ContentPresenter x:Name="ContentSite"
										VerticalAlignment="{TemplateBinding VerticalAlignment}"
										HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
										ContentSource="Header"
										Margin="0"
										RecognizesAccessKey="True" />
						</Border>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
			<Setter Property="HeaderTemplate">
				<Setter.Value>
					<DataTemplate>
						<DockPanel>
							<Button DockPanel.Dock="Right" BorderThickness="0" Background="Transparent" Cursor="Hand" 
								Command="{Binding DataContext.CloseCommand, RelativeSource={RelativeSource AncestorType= TabItem}}"
								CommandParameter="{Binding (commonViews:Attached.ViewService), RelativeSource={RelativeSource AncestorType=TabItem}}">
								<Button.Template>
									<ControlTemplate TargetType="Button">
										<Image Source="Images\CloseTab-Gray.png" Width="16" Height="16" Margin="2 0 2 0">
											<VisualStateManager.VisualStateGroups>
												<VisualStateGroup>
													<VisualState x:Name="MouseOver">
														<Storyboard>
															<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source">
																<DiscreteObjectKeyFrame KeyTime="0:0:0">
																	<DiscreteObjectKeyFrame.Value>
																		<BitmapImage UriSource="/Albatross;component/Images/CloseTab.png" />
																	</DiscreteObjectKeyFrame.Value>
																</DiscreteObjectKeyFrame>
															</ObjectAnimationUsingKeyFrames>
														</Storyboard>
													</VisualState>
													<VisualState x:Name="Normal" />
													<VisualState x:Name="Disabled" />
												</VisualStateGroup>
											</VisualStateManager.VisualStateGroups>
										</Image>
									</ControlTemplate>
								</Button.Template>
							</Button>
							<TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="12" VerticalAlignment="Stretch" Margin="10 3 3 3" />
						</DockPanel>
					</DataTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<Style TargetType="Menu" x:Key="menu">
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="Margin" Value="2"/>
		</Style>
		
		<Style TargetType="MenuItem" x:Key="menuitem">
			<Setter Property="Padding" Value="5 3 5 3"/>
		</Style>

		<ContextMenu x:Key="workspace_dropdown" Initialized="WorkspaceDropDownMenu_Initialized"
				 ItemsSource="{Binding Items, ElementName=MainTabControl}" 
				 ItemContainerStyle="{StaticResource workspace_menuitem}" />

		<Style TargetType="{x:Type TabControl}" x:Key="tabcontrol">
			<Setter Property="Background" Value="{StaticResource tabcontrol_background}"/>
			<Setter Property="ItemContainerStyle" Value="{StaticResource tabitem}"/>
			<Setter Property="BorderBrush" Value="{StaticResource tabcontrol_border}"/>
			<Setter Property="Margin" Value="2"/>
			<Setter Property="OverridesDefaultStyle" Value="True" />
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type TabControl}">
						<DockPanel KeyboardNavigation.TabNavigation="Local">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Disabled">
										<Storyboard>
											<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
												<EasingColorKeyFrame KeyTime="0" Value="#FFAAAAAA" />
											</ColorAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<DockPanel DockPanel.Dock="Top">
								<Button DockPanel.Dock="Right" VerticalAlignment="Bottom" ContextMenu="{StaticResource workspace_dropdown}" Click="WorkspaceDropDownBtn_Click">
									<Image Width="16" Height="16" Source="/Images/down.png"/>
									<Button.Template>
										<ControlTemplate TargetType="Button">
											<ContentPresenter />
										</ControlTemplate>
									</Button.Template>
									<Button.Style>
										<Style TargetType="Button">
											<Style.Triggers>
												<DataTrigger Binding="{Binding Items.Count, ElementName=MainTabControl}" Value="0">
													<Setter Property="Visibility" Value="Collapsed"/>
												</DataTrigger>
											</Style.Triggers>
										</Style>
									</Button.Style>
								</Button>
								<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1 0 0 0" DockPanel.Dock="Top">
									<TabPanel x:Name="HeaderPanel" 
										  IsItemsHost="True" 
										  KeyboardNavigation.TabIndex="1" 
										  Background="Transparent" />
								</Border>
							</DockPanel>
							<Border x:Name="Border" 
								BorderThickness="1" 
								BorderBrush="{TemplateBinding BorderBrush}" 
								Background="{TemplateBinding Background}"
								KeyboardNavigation.TabNavigation="Local" 
								KeyboardNavigation.DirectionalNavigation="Contained" 
								KeyboardNavigation.TabIndex="2">
								<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" />
							</Border>
						</DockPanel>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</Window.Resources>
	
	<DockPanel>
		<Menu DockPanel.Dock="Top" x:Name="MainMenu" Style="{StaticResource menu}" ItemContainerStyle="{StaticResource menuitem}">
			<MenuItem Header="File">
				<MenuItem Header="New" Command="{Binding NewWindowCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource new app img}"/>
				<Separator/>
				<MenuItem Header="Favorites">
					<MenuItem Header="Manage" Command="{Binding ManageFavoritesCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource favorite img}"/>
					<Separator/>
				</MenuItem>
				<Separator/>
				<MenuItem Header="Options" Command="{Binding OptionsCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource options img}"/>
				<MenuItem Header="System" Command="{Binding SystemCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource system img}"/>
				<MenuItem Header="About" Command="{Binding AboutCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource about img}"/>
				<Separator/>
				<MenuItem Header="Exit" Command="{Binding ExitCommand}" CommandParameter="{Binding (commonViews:Attached.ViewService)}" Icon="{StaticResource exit img}"/>
			</MenuItem>
		</Menu>
		<TabControl x:Name="MainTabControl"  Style="{StaticResource tabcontrol}" DockPanel.Dock="Bottom">
		</TabControl>
	</DockPanel>
</Window>